package com.ruoyi.biz.plan.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.biz.plan.domain.BizPlanConfig;
import com.ruoyi.biz.plan.service.IBizPlanConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 计划配置Controller
 *
 * @author Fei.Cong
 * @date 2024-07-13
 */
@RestController
@RequestMapping("/plan/config" )
public class BizPlanConfigController extends BaseController {

    @Autowired
    private IBizPlanConfigService bizPlanConfigService;

    /**
     * 查询计划配置列表
     */
    @PreAuthorize("@ss.hasPermi('plan:config:list')" )
    @GetMapping("/list" )
    public AjaxResult list(BizPlanConfig bizPlanConfig) {
        LambdaQueryWrapper<BizPlanConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        return success(bizPlanConfigService.list(lambdaQueryWrapper));
    }

    /**
     * 分页查询计划配置列表
     */
    @PreAuthorize("@ss.hasPermi('plan:config:list')" )
    @GetMapping("/page" )
    public TableDataInfo page(BizPlanConfig bizPlanConfig) {
        return getDataTable(bizPlanConfigService.pageList(bizPlanConfig, startPage()));
    }

    /**
     * 导出计划配置列表
     */
    @PreAuthorize("@ss.hasPermi('plan:config:export')" )
    @Log(title = "计划配置" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, BizPlanConfig bizPlanConfig) {
        List<BizPlanConfig> list = bizPlanConfigService.queryList(bizPlanConfig);
        ExcelUtil<BizPlanConfig> util = new ExcelUtil<BizPlanConfig>(BizPlanConfig.class);
        util.exportExcel(response, list, "计划配置数据" );
    }

    /**
     * 获取计划配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('plan:config:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return success(bizPlanConfigService.getById(id));
    }

    /**
     * 新增计划配置
     */
    @PreAuthorize("@ss.hasPermi('plan:config:add')" )
    @Log(title = "计划配置" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizPlanConfig bizPlanConfig) {
        return toAjax(bizPlanConfigService.save(bizPlanConfig));
    }

    /**
     * 修改计划配置
     */
    @PreAuthorize("@ss.hasPermi('plan:config:edit')" )
    @Log(title = "计划配置" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizPlanConfig bizPlanConfig) {
        return toAjax(bizPlanConfigService.updateById(bizPlanConfig));
    }

    /**
     * 删除计划配置
     */
    @PreAuthorize("@ss.hasPermi('plan:config:remove')" )
    @Log(title = "计划配置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(bizPlanConfigService.removeBatchByIds(ids));
    }
}
